﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>轻松拖曳窗口 - 脚本示例 | AutoHotkey v2</title>
<meta name="description" content="This script allows moving a window by holding down CapsLock or the middle mouse button while clicking on any point inside a window." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Easy Window Dragging(轻松拖曳窗口)</h1>

<p>一般情况下只能通过点击标题栏来拖动窗口. 这个脚本扩展到可以在窗口中任何一点拖动窗口. 要激活这种模式, 请在点击时按住 <kbd>CapsLock</kbd> 或鼠标中键, 然后拖动窗口到新的位置.
</p>
<p><a href="EasyWindowDrag.ahk">下载此脚本</a> &nbsp;| &nbsp;<a href="index.htm">其他示例脚本</a> &nbsp;| &nbsp;<a href="../AutoHotkey.htm">主页</a></p>

<pre class="NoIndent"><em>;注意: 在按下鼠标按钮后您可以释放 <kbd>CapsLock</kbd> 或鼠标中键
; 而不需要在整个拖动过程中按住它.</em>

~MButton &amp; LButton::
CapsLock &amp; LButton::
EWD_MoveWindow()
{
    CoordMode "Mouse"  <em>; 切换到屏幕/绝对坐标.</em>
    MouseGetPos EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
    WinGetPos EWD_OriginalPosX, EWD_OriginalPosY,,, "ahk_id " EWD_MouseWin
    if !WinGetMinMax("ahk_id " EWD_MouseWin)  <em>; 仅在窗口不处于最大化状态时 </em>
        SetTimer "EWD_WatchMouse", 10 <em>; 在用户拖动时跟踪鼠标.</em>

    EWD_WatchMouse()
    {
        if !GetKeyState("LButton", "P")  <em>; 按钮已经释放, 所以拖动结束.</em>
        {
            SetTimer, 0
            return
        }
        if GetKeyState("Escape", "P")  <em>; 按下了 Escape, 所以取消拖动.</em>
        {
            SetTimer, 0
            WinMove EWD_OriginalPosX, EWD_OriginalPosY,,, "ahk_id " EWD_MouseWin
            return
        }
        <em>; 否则, 改变窗口的位置以匹配
; 用户拖动鼠标引起的鼠标坐标变化:</em>
        CoordMode "Mouse"
        MouseGetPos EWD_MouseX, EWD_MouseY
        WinGetPos EWD_WinX, EWD_WinY,,, "ahk_id " EWD_MouseWin
        SetWinDelay -1   <em>; 让下面的移动更快速/平滑.</em>
        WinMove EWD_WinX + EWD_MouseX - EWD_MouseStartX, EWD_WinY + EWD_MouseY - EWD_MouseStartY,,, "ahk_id " EWD_MouseWin
        EWD_MouseStartX := EWD_MouseX  <em>; 为下一次调用此子程序进行更新.</em>
        EWD_MouseStartY := EWD_MouseY
    }
}
</pre>
</body>
</html>